package test6;

public class PhoneTest {
    public static void main(String[] args) {
        //1.创建数组
        Phone[] arr = new Phone[3];

        //2.创建对象
        Phone p1 = new Phone("小米",1400,"白色");
        Phone p2 = new Phone("华为",2300,"红色");
        Phone p3 = new Phone("vivo",2500,"蓝色");

        //3.把手机对象添加到数组当中
        arr[0] = p1;
        arr[1] = p2;
        arr[2] = p3;

        //4.获取三部手机的平均价格
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            Phone p = arr[i];
            sum+=p.getPrice();
        }

        //5.求平均价格
        //double avg = sum/arr.length;写的有点死
        double avg = sum*1.0 / arr.length;

        System.out.println(avg);

    }
}
